import 'package:flutter_model_package/Member.dart';
import 'package:flutter_model_package/util/number_code.dart';
import 'package:parse_server_sdk/parse_server_sdk.dart';

class Scholar extends ParseObject implements ParseCloneable{
  Scholar() : super("Scholar");
  Scholar.clone() : this();
  @override
  Scholar clone(Map<String, dynamic> map) => Scholar.clone()..fromJson(map);

  static Future<Scholar> addNewScholar(String name,Member member) async {
    Scholar scholar = new Scholar();
    Scholar scholar2 = new Scholar();
    if(member["scholar"]!=null){
      scholar2 = member['scholar'];
    }else{
      scholar.set("number", NumberCode.code());
      scholar.set("displayName", name);
      var rep = await scholar.save();
      if(rep.success){
        scholar2.set("objectId", rep.result["objectId"]);
      }
    }
    return scholar2;
  }
}